local skel = fk.CreateSkill{
  name = "ksp__zhuochen",
}

Fk:loadTranslationTable{
  ["ksp__zhuochen"] = "灼辰",
  [":ksp__zhuochen"] = "出牌阶段限一次，或当你死亡时，你可以连续视为使用【火攻】：首张无目标数限制，此后每张的目标数上限为上张造成的伤害值。",
 
  ["@ksp__zhuochen-phase"] = "灼辰",
  ["#ksp__zhuochen"] = "灼辰：你可以视为对任意名角色使用【火攻】",

  ["$ksp__zhuochen1"] = "应变将略，出汉川，捣扶风，定长安，襄定十年功，足压乐管。",
  ["$ksp__zhuochen2"] = "代嗣靖国，受九锡，明仪轨，登天陛，挥斥三军静，红旌林立。",
}

skel:addEffect("active", {
  mute = true,
  prompt = "#ksp__zhuochen",
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name,Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return player:canUseTo(Fk:cloneCard("fire_attack"),to_select)
  end,
  min_target_num = 1,
  on_use = function (self, room, effect)
    local player = effect.from
    room:notifySkillInvoked(player,skel.name,nil,effect.tos)
    player:broadcastSkillInvoke(skel.name)
    local card = Fk:cloneCard("fire_attack")
    card.skillName = skel.name
    room:useCard{
      from = player,
      card = card,
      tos = effect.tos,
    }
    while player:getMark("@ksp__zhuochen-phase") > 0 and not player:isKongcheng() do
      player:broadcastSkillInvoke(skel.name)
      room:askToUseVirtualCard(player,{
        name = "fire_attack",
        skill_name = skel.name,
        cancelable = false,
      })
    end
  end,
})

skel:addEffect(fk.Death, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name,false,true) and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local list = room:getTag(skel.name) or {}
    table.insertIfNeed(list,player.id)
    room:setTag(skel.name,list)
    room:askToUseActiveSkill(player,{
      skill_name = skel.name,
      prompt = "#ksp__zhuochen"
    })
    list = room:getTag(skel.name) or {}
    table.removeOne(list,player.id)
    room:setTag(skel.name,list)
  end,
})

skel:addEffect(fk.CardUseFinished, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name,false,true) and target == player and data.card.skillName == skel.name
  end,
  on_refresh = function(self, event, target, player, data)
    local n = 0
    if data.damageDealt then
      for _, v in pairs(data.damageDealt) do
        n = n + v
      end
    end
    player.room:setPlayerMark(player,"@ksp__zhuochen-phase",n)
  end,
})

skel:addEffect("targetmod", {
  extra_target_func = function(self, player, skill, card)
    if card.skillName == skel.name then
      return (player:getMark("@ksp__zhuochen-phase") - 1)
    end
  end,
})

return skel